package com.huiquan.framework.dao;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.framework.domain.ActionRecord;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class ActionRecordDao extends EnhancedBaseDao<ActionRecord> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "ACTION_RECORDD.";

	public ActionRecordDao() {
		super(space);
	}

	public Long insertByType(Integer type, User user) {
		ActionRecord ar = new ActionRecord();
		ar.setType(type);
		ar.setStatus(ActionRecord.STATUS_UNCOMPLETED);
		ar.setCreatorId(user.getUserId());
		ar.setCreatorName(user.getRealName());
		ar.setModifierId(user.getUserId());
		ar.setModifierName(user.getRealName());
		
		return insert(ar);
	}

	public void completeById(Long recordId) {
		Map<String, Object> param = new HashMap<>();
		param.put("id", recordId);
		
		this.update(space + "COMPLETE_BY_ID", param, sqlMapClient);
	}

	public ActionRecord retrieveUncompletedByType(Integer type) {
		Map<String, Object> param = new HashMap<>();
		param.put("type", type);
		
		return (ActionRecord)this.object(space + "RETRIEVE_UNCOMPLETED_BY_TYPE", param, sqlMapClient);
	}

}
